﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Reflection;
using System.Text;

namespace KeyCore.Framework.Contexts
{
    public class BaseContext<T> : DbContext where T : DbContext
    {
        static BaseContext()
        {
            Database.SetInitializer<T>(null);
        }

        protected BaseContext()
            : base("name=DbConnection")
        {

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // load all EntityTypeConfiguration from domain assembly
            modelBuilder.Configurations.AddFromAssembly(Assembly.Load("KeyCore.Domain"));
            // Configure Code First to ignore PluralizingTableName convention
            // If you keep this convention then the generated tables will have pluralized names.
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            base.OnModelCreating(modelBuilder);
        }
    }
}
